package usbcali.edu.co.pqrs.dataaccess.dao;

import java.sql.Blob;
import java.util.Date;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.engine.jdbc.BinaryStream;
import org.hibernate.transform.Transformers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import usbcali.edu.co.pqrs.dataaccess.api.HibernateDaoImpl;
import usbcali.edu.co.pqrs.modelo.AnexosSolicitante;
import usbcali.edu.co.pqrs.modelo.dto.SolicitudPqrDTO;

/**
 * A data access object (DAO) providing persistence and search support for
 * AnexosSolicitante entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see lidis.AnexosSolicitante
 */
@Scope("singleton")
@Repository("AnexosSolicitanteDAO")
public class AnexosSolicitanteDAO extends
		HibernateDaoImpl<AnexosSolicitante, Long> implements
		IAnexosSolicitanteDAO {
	private static final Logger log = LoggerFactory
			.getLogger(AnexosSolicitanteDAO.class);
	@Resource
	private SessionFactory sessionFactory;

	public static IAnexosSolicitanteDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (IAnexosSolicitanteDAO) ctx.getBean("AnexosSolicitanteDAO");
	}

	@Override	
	public void crearAnexoSolicitante(Blob blob, String nombreAnexo,
			String nombreBusqueda, String estado, Long idSolicitud, Long idAnexo, Date fecha) {
		try {			   
			   Query query = getSession().getNamedQuery("insertar_anexo");
			   query.setParameter("pBlob", blob);
			   query.setParameter("pNombreAnexo", nombreAnexo);
			   query.setParameter("pNombreBusqueda", nombreBusqueda);
			   query.setParameter("pEstadoRegistro", estado);
			   query.setParameter("pIdSolicitud", idSolicitud);
			   query.setParameter("pIdAnexo", idAnexo);
			   query.setParameter("pFecha", fecha);
			   query.setResultTransformer(Transformers.aliasToBean(AnexosSolicitante.class));
			   query.executeUpdate();
			   
			  } catch (Exception e) {
			    e.printStackTrace();
			  }
		
	}
}
